const express = require('express')

module.exports = function () {
  let router = express.Router()

  router.use((req, res, next) => {
    if (!req.session['admin_id'] && req.url !== '/login') {
      res.redirect('/admin/login')  // redirect 重定向
    } else {
      next()
    }
  })

  router.get('/', (req, res) => {
    res.render('admin/index.ejs', {}) // 登录成功
  })

  router.use('/login', require('./login')())
  router.use('/banners', require('./banners')())
  router.use('/custom', require('./custom')())
  router.use('/contact', require('./contact')())
  router.use('/blog', require('./blog')())
  router.use('/intro', require('./intro')())
  router.use('/msg', require('./msg')())
  router.use('/news', require('./news.js')())

  return router
}
